// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-7-5

#include "stdafx.h"
#include ".\label.h"

//##ModelId=44CF17B80070
CJoyLabel::CJoyLabel(void)
{
    m_skinArea = true;
    m_trimming      = StringTrimmingEllipsisWord;
    m_formatFlags   = StringFormatFlagsNoWrap;
    m_textAlign     = StringAlignmentNear;
}

//##ModelId=44CF17B80072
CJoyLabel::~CJoyLabel(void)
{
}

//##ModelId=44CF17B80075
void CJoyLabel::SetText(PCSTR text)
{
    m_text = text;
    InvalidateCtrl();
}

//##ModelId=44CF17B8007F
void CJoyLabel::SetTextAlign(StringAlignment textAlign)
{
    m_textAlign     = textAlign;
    InvalidateCtrl();
}
//##ModelId=44CF17B80081
void CJoyLabel::SetTextFormat(StringFormatFlags FormatFlag)
{
    m_formatFlags     = FormatFlag;
    InvalidateCtrl();
}

//##ModelId=44CF17B80067
void CJoyLabel::CM_LoadSkin(CJoyXmlElement* pSkinElem)
{
    __super::CM_LoadSkin(pSkinElem);
    if(m_text.IsEmpty())
    {
        m_text = pSkinElem->ReadString("text");
    }
}

//##ModelId=44CF17B8006D
void CJoyLabel::CM_Draw(Graphics& graph)
{
    StringFormat sf;
    sf.SetLineAlignment(StringAlignmentCenter);
    sf.SetTrimming(m_trimming);
    sf.SetFormatFlags(m_formatFlags);
    sf.SetAlignment(m_textAlign);

    SolidBrush txBrush(m_textColor);

    FontFamily fam(m_textFace);
    Font font(&fam, (REAL)m_textSize, FontStyleRegular, UnitPixel);

    graph.DrawString(
        m_text, m_text.GetLength(),
        &font,
        RectF((REAL)0, (REAL)0, (REAL)m_area.Width(), (REAL)m_area.Height()),
        &sf, &txBrush);
}
